package mvc.effects.impl;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import mvc.effects.INonParameterizedEffect;

@SuppressWarnings("nls")
public class GrayscaleEffect implements INonParameterizedEffect {

	private BufferedImageOp grayscale;
	private final String EFFECT_NAME = "Greyscale";

	@Override
	public BufferedImage applyEffect(BufferedImage img) {
		int width = img.getWidth(), height = img.getHeight();
		int originalColorType = img.getType();
		BufferedImage temp, temp2;

		temp = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
		Graphics g = temp.getGraphics();
		g.drawImage(img, 0, 0, null);
		g.dispose();

		temp2 = new BufferedImage(width, height, originalColorType);
		g = temp2.getGraphics();
		g.drawImage(temp, 0, 0, null);
		g.dispose();
		return temp2;
	}

	@Override
	public BufferedImageOp getEffect() {
		return grayscale;
	}

	@Override
	public String toString() {
		return EFFECT_NAME;
	}

}
